package com.zsh.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.zsh.domain.UamUserMenu;
import com.zsh.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(value = "用户菜单", tags = "用户菜单", description = "用户菜单", produces = "application/json;charset=utf-8")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @RequestMapping(value = "/queryMenu",method = {RequestMethod.POST,RequestMethod.GET})
    @ApiOperation(value="queryMenu", notes="swaggerUI测试",httpMethod="POST")
    @HystrixCommand(fallbackMethod = "queryMenuFallback",
            commandProperties=@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1000"))
    public List<UamUserMenu> queryMenu(@RequestBody UamUserMenu param) throws InterruptedException {
        List<UamUserMenu> uamUserMenuList = menuService.queryMenu(param.getUserId());
        System.out.println("服务器b………………………………………………");
        return uamUserMenuList;
    }

    public List<UamUserMenu> queryMenuFallback(@RequestBody UamUserMenu param){
        UamUserMenu uam = new UamUserMenu();
        uam.setId("111");
        uam.setMenuId("111");
        uam.setUserId("111");
        uam.setYn(1);
        List<UamUserMenu> uamUserMenuList = new ArrayList<>();
        uamUserMenuList.add(uam);
        return uamUserMenuList;
    }
}